setClass("EntropySelectionReducer",contains="Reducer",
		representation(
				.selectionCrit="character",
				.tmpWeights = "data.frame"
				),
		prototype=prototype(
				.description="Entropy selection Reducer Class",
				.selectionCrit="information.gain",
				.tmpWeights =data.frame()
		),
		validity=function(.Object){
			if(! is(.Object@.dimChooser,"EntropyDimChooser")){
				stop("EntropySelectionReducer must be initialized by EntropyDimChooser object. EntropySelectionReducer was initialized by ",class(.Object@.dimChooser))
			}
			if( !(.Object@.selectionCrit=="information.gain" ||.Object@.selectionCrit=="gain.ratio"||.Object@.selectionCrit=="symmetrical.uncertainty")){
				stop("bad function name ",.Object@.selectionCrit)
			}
		}
)
#TODO need to concatenate set with classes

#methods
setMethod("initialize",
		signature="EntropySelectionReducer",
		function(.Object,dimChooser,selectionCrit="information.gain",...){
			.Object <-callNextMethod(.Object,dimChooser,...);
			.Object@.selectionCrit <- selectionCrit
			validObject(.Object)
			return(.Object)
		})

setMethod("reduce",
		signature="EntropySelectionReducer",
		definition=function(.Object,inputSet,classes,...){

			inCols <-ncol(inputSet)
			weights <- unlist( lapply(1:inCols, FUN=function(n,set,classes){
								feature <-discretize(set[,n],disc="equalwidth") 
								IG<- mutinformation(classes,feature)
							},inputSet,classes ) )
			
			.Object@.tmpWeights <- as.data.frame(weights)
			rownames(.Object@.tmpWeights) <- as.character(1:inCols)
			colnames(.Object@.tmpWeights) <-"C1"

		
			dim <-chooseBest(.Object@.dimChooser,.Object)	
			sorted_names <- rownames(.Object@.tmpWeights)[order(.Object@.tmpWeights, decreasing = TRUE)]
			retSet <-inputSet[,as.numeric(sorted_names[1:dim]),drop=FALSE]
			.Object@.resEnv$savedSet <- retSet
			return(retSet)
			
		})




